package test;

import java.io.UnsupportedEncodingException;
import java.security.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.codec.binary.Base64;

/**
 *
 * @author Tom
 */
public class test2 
{
    public static void main(String[] args) throws UnsupportedEncodingException
    {
        try 
        {
            KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
            kpg.initialize(2048);
            KeyPair kp = kpg.genKeyPair();
            Key publicKey = kp.getPublic();
            Key privateKey = kp.getPrivate();
            
            Base64 encoder = new Base64();
            String pub = encoder.encodeToString(publicKey.getEncoded());
            String pri = encoder.encodeToString(privateKey.getEncoded());
            System.out.println(pub);
            System.out.println("");
            System.out.println(pri);
  
        } 
        catch (NoSuchAlgorithmException ex) {
            Logger.getLogger(test2.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
